#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time : 2021-11-30 10:31
# @Author : huabao.tan
# @File : base_page.py
# @Software: PyCharm
"""
    基于常用的selenium函数来进行二次封装， 生成自定义函数类。
    再提供至PageObject类进行调用。
"""

from selenium import webdriver
from time import sleep

def open_browser(txt):
    try:
        driver = getattr(webdriver, txt)()

    except Exception as e:
        print(e)
        driver = webdriver.Chrome()
    return driver


class BasePage:
    def __init__(self, txt):
        self.driver = open_browser(txt)

    def max(self):
        self.driver.maximize_window()

    # 访问URL
    def open(self, url):
        self.driver.get(url)

    # 查找元素
    def locator(self, txt):
        return self.driver.find_element(*txt)

    # 输入
    def input(self, txt, txt1):
        self.locator(txt).send_keys(txt1)

    # 点击
    def click(self, txt):
        self.locator(txt).click()

    # 等待
    def wait(self, time_):
        sleep(time_)

    # 鼠标向下滚动
    def roll_max(self, txt):
        js = ("var q=document.documentElement.scrollTop='%s'".format(txt))
        self.driver.execute_script(js)
        self.wait(3)

    # 切换表单
    def switch(self, txt):
        self.driver.switch_to.frame(txt)


    #关闭浏览器
    def quint(self):
        self.driver.quit()
